package dao

import (
	"ssims/models"
)

func GetAllMember(member map[string]interface{}) (error, []models.Member, int64) {
	var memberData []models.Member
	page := member["page"].(int)
	pageSize := member["limit"].(int)
	searchName := member["searchName"].(string)
	var total int64
	err := db.Table("member").Select("member_no, member_name, member_sex, birthday, deathday, dept_name,  update_time").Where("member_name like ? and is_del = false", searchName+"%").Order("member_no ASC").Count(&total).Offset((page - 1) * pageSize).Limit(pageSize).Find(&memberData).Error
	return err, memberData, total
}

func DelMember(id string) error {
	// var Member []models.Member
	err := db.Table("member").Where("member_no = ?", id).Update("is_del", true).Error
	return err
}

func UpdateMember(member models.Member) error {
	err := db.Table("member").Where("member_no = ?", member.MemberNo).Updates(&member).Error
	return err
}

func AddMember(member models.Member) error {
	err := db.Table("member").Select("member_no", "member_name", "member_sex", "birthday", "deathday", "dept_name", "update_time", "is_del").Create(&member).Error
	return err
}
